package com.example.album;

import jakarta.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "likes")
@IdClass(Like.LikeId.class)
public class Like {
    @Id
    @Column(name = "user_id", nullable = false, length = 16)
    private String userId;

    @Id
    @Column(name = "album_id", nullable = false, length = 16)
    private String albumId;

    // getter 和 setter
    public String getUserId() { return userId; }
    public void setUserId(String userId) { this.userId = userId; }

    public String getAlbumId() { return albumId; }
    public void setAlbumId(String albumId) { this.albumId = albumId; }

    // 联合主键类
    public static class LikeId implements Serializable {
        private String userId;
        private String albumId;

        public LikeId() {}
        public LikeId(String userId, String albumId) {
            this.userId = userId;
            this.albumId = albumId;
        }
        // equals 和 hashCode 必须重写
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            LikeId likeId = (LikeId) o;
            return userId.equals(likeId.userId) && albumId.equals(likeId.albumId);
        }
        @Override
        public int hashCode() {
            return java.util.Objects.hash(userId, albumId);
        }
    }
}
